﻿package view;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;

import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter.DEFAULT;

import model.audio.AudioCaptureModel;
import model.audio.AudioMixerModel;
import model.audio.SoundProcessor;
import model.audio.Interface.AudioStateObserver;
import model.audio.Interface.DBObserver;
import model.drawPanel.DrawPanelModel;
import model.drawPanel.Interface.IDrawObserver;
import model.drawPanel.Interface.IDrawPanelModel;
import model.drawPanel.entitys.*;
import model.roomManagement.Implementation.RoomManageModel;
import model.roomManagement.Implementation.User;
import model.roomManagement.Interface.ViewObserver;
import model.textChat.Message;
import model.textChat.Interface.MessageObserver;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.wb.swt.SWTResourceManager;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.MouseTrackListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.widgets.Scale;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.TextStyle;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;

import controller.audio.AudioController;
import controller.audio.Interface.IAudioController;
import controller.drawPanel.DrawPanelController;
import controller.drawPanel.Interface.IDrawPanelController;
import controller.fshare.ClientFileShareController;
import controller.fshare.Interface.ClientFileShareControl;
import controller.textChat.TextChatController;
import controller.textChat.Interface.TextChatControl;

import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;

import model.infocenter.ClientUserInformations;


public class GMS implements AudioStateObserver,DBObserver,IDrawObserver,MessageObserver,ViewObserver{
	private IDrawPanelController dpc;
	private TextChatControl tcc;
	private IAudioController IAC;
	private RoomManageModel RMM;
	private int roomID;
	
	private User[] userList = new User[8];//8个用户
	//private ArrayList<User> userAList = new ArrayList<User>();
	private String authorityIP = "0";//拥有权限的用户的IP，没有人有权限时为字符"0"
	private Display display;
	protected Shell shlGms;
	private ShellManager sm;
	
	private StyledText text_chat;
	private StyledText text_send;
	private Label lbl_powerInfo;
	
	private Label_draw[] ld = new Label_draw[7];//7个缩略图组件
	private int focusIndex = 0;//获得焦点的缩略图索引
	private int totalLabel = 0;//当前面板的总数
	private Label lbl_lastWarning;
	private Label lbl_nextWarning;
	private Label lbl_penWarning;
	private Label lbl_NDWarning;
	private int noPowerFocusIndex = 0;//无权限的焦点
	private int noPowerTotalLabel = 0;//无权限的面板总数
	
	private CompositeUser[] cu = new CompositeUser[8];//8个用户头像面板
	private int userFocusIndex = -1;//-1表示没有人持有画笔
	private boolean hasPen = false;//本地用户是否持有画笔
	private Button btn_pencil;
	private Composite composite_chat;
	private Composite composite_thin;
	private Composite composite_line;
	private Composite composite_color;
	
	private int size = 0;//画笔/橡皮的粗细度0，1，2，3，4，像素大小为5，10，15，20，25
	private int dotted = 0;//线条风格直线，虚线
	private Color color;//颜色,默认黑色
	
	private ToolItem tltm_mic;
	private ToolItem tltm_vol;
	
	private ProgressBar progressBar;//当前麦克风分贝进度条
	private Download download;
	
	//private boolean msgOpen;
	
	//聊天记录变量声明******************************************************************************
	private Button btn_la;
	private Button btn_ne;
	private Label lbl_chatPage;
	private ToolItem tltm_chatlogs;
	private Button btn_addChatlogs;
	private static int MAX_CHATLOGS = 10;
	private String[] chatlogs = new String[MAX_CHATLOGS];
	private int currentChatlogsP = 0;
	private int totalChatlogsP = 0;
	//聊天记录变量声明***结束***************************************************************************
	
	//鼠标手势声明**************************************************************************
	private Cursor cs_arrow;   //箭头
	private Cursor cs_hand;    //小手
    private Cursor cs_cross;   //十字
    private Cursor cs_pen0;     //笔
    private Cursor cs_pen1;
    private Cursor cs_pen2;
    private Cursor cs_pen3;
    private Cursor cs_pen4;
    private Cursor cs_rubber0;  //橡皮
    private Cursor cs_rubber1;
    private Cursor cs_rubber2;
    private Cursor cs_rubber3;
    private Cursor cs_rubber4;
    private Cursor cs_fill;   //填充
    //鼠标手势声明***结束*************************************************************************
    
    //文本框窗口的响应变量声明**************************************************************************
    private File file;
    private File[] fList;
    private int totalPage = 0;
    private int currentPage = 1;
    private static int MAX_TXT = 20;
    private String[] textString = new String[MAX_TXT];//最多20个txt
    private Text text_chatlogs;
    private StyledText text;
    //文本框窗口的响应变量声明***结束**********************************************************************
    
    //**************************************wbr***************************************start
    private int tool;
    private Canvas drawPanel;
    private Button btn_authority;
    private StyledText textInput;
    @Override
	public void refresh() {// panelNum 来判断是否增删panel
    			Runnable runnable = new Runnable(){
    				public void run (){
    						drawPanel.redraw();
    					}
    			};
    			Display.getDefault().asyncExec(runnable);
	}
	@Override
	public void updateAuthoriy(String authorityMsg) {
		// TODO Auto-generated method stub
		final String am = authorityMsg;
		if(!shlGms.isDisposed() && !cu[0].getHead().isDisposed()){
			//失去画笔消息提示***********************************************************************
			if(am.equals("0")){
				for(int i=0;i < userList.length;i++){
					if(userList != null){
						if(userList[i].getIp().equals(authorityIP)){
							final int index = i;
							display.asyncExec(new Runnable(){
								public void run(){
									long timemillis = System.currentTimeMillis();	 
									SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");//转换日期显示格式  
									
									int startIndex = text_chat.getText().length(); 
									String msg = df.format(new Date(timemillis)) + " " + userList[index].getName() + " "
											+ "放弃了画笔" +'\n';
									text_chat.append(msg);
									text_chat.setStyleRange(getColorStyle(startIndex, msg.length(), 
											SWTResourceManager.getColor(255, 165, 0)));
									text_chat.setSelection(text_chat.getText().length()-1);//光标移到最下方
									cu[index].lostFocus();
								}
							});
							authorityIP = "0";
							userFocusIndex = -1;
							break;
						}
					}
				}
				//System.out.println("authorityIP000,"+authorityIP);
				//System.out.println("am000,"+am);
				return;
			}
			//失去画笔消息提示***结束******************************************************************
			
			boolean authoriy = false;
			for(int i=0;i<userList.length;i++){
				if(userList[i]!=null){
					if(userList[i].getIp().equals(am)){
						authoriy = true;
						final int index = i;
						display.asyncExec(new Runnable(){
							public void run(){
								cu[index].setFocus();
								userFocusIndex = index;
								//获得画笔消息提示***********************************************************************
								//System.out.println("authorityIP"+authorityIP);
								//System.out.println("am"+am);
								if(!authorityIP.equals(am)){
									
									long timemillis = System.currentTimeMillis();	 
									SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");//转换日期显示格式  
									
									int startIndex = text_chat.getText().length(); 
									String msg = df.format(new Date(timemillis)) + " " + userList[index].getName() + " "
											+ "获得了画笔" +'\n';
									text_chat.append(msg);
									text_chat.setStyleRange(getColorStyle(startIndex, msg.length(), 
											SWTResourceManager.getColor(255, 165, 0)));
									text_chat.setSelection(text_chat.getText().length()-1);//光标移到最下方
								}
								
								//获得画笔消息提示***结束******************************************************************
								if(ClientUserInformations.getInstance().getIp().equals(am)){
									btn_pencil.setImage(SWTResourceManager.getImage(GMS.class, "/img/pencilColor_34.png"));
									btn_pencil.setToolTipText("放弃画笔");
									hasPen = true;
									//System.out.println("authorityIPforcus"+authorityIP);
									//System.out.println("amforcus"+am);
									
									focusIndex = noPowerFocusIndex;
									totalLabel = noPowerTotalLabel;
									
									//System.out.println(focusIndex);
									//System.out.println(totalLabel);
								}
								authorityIP = am;
							}
							
						});
						
					}
					else{
						final int index = i;
						display.asyncExec(new Runnable(){
							public void run(){
								cu[index].lostFocus();
							}
						});
					}
				}
			}
			if(!authoriy){
				userFocusIndex = -1;
			}
		}
	}
    //**************************************wbr***************************************end
	/**
	 * Launch the application.
	 * @param args
	 */
/*	public static void main(String[] args) {
		try {
			GMS window = new GMS();
			window.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public GMS(){
		
	}*/
	public GMS(RoomManageModel RMM,int roomID){
		this.RMM = RMM;
		RMM.addViewObserver(this);
		//roomID = RMM.getRoomId();
		this.roomID = roomID;
		display = Display.getDefault();
		init();//初始化界面
		//初始化controller******************************************************************************		
		IAC = new AudioController(this, this);
		IAC.startAudioSession();	
		tcc = new TextChatController(this);
		
		//初始化各种controller***结束***************************************************************************
	    sm = new ShellManager();
	}
	
	private void init(){
		dpc =new DrawPanelController(this,roomID);
		dpc.setWidth(10);
		dpc.setColor(SWTResourceManager.getColor(SWT.COLOR_BLACK));
		//鼠标手势****************************************************************************************
		cs_arrow = new Cursor(display,SWT.CURSOR_ARROW);
		cs_hand = new Cursor(display,SWT.CURSOR_HAND);
		cs_cross = new Cursor(display,SWT.CURSOR_CROSS);
		//画笔手势
		ImageData id_pen0 =new ImageData("cursor\\pen_7.png");
		ImageData id_pen1 =new ImageData("cursor\\pen_11.png");
		ImageData id_pen2 =new ImageData("cursor\\pen_15.png");
		ImageData id_pen3 =new ImageData("cursor\\pen_19.png");
		ImageData id_pen4 =new ImageData("cursor\\pen_24.png");
		cs_pen0 = new Cursor(display, id_pen0, 2, 2);
		cs_pen1 = new Cursor(display, id_pen1, 4, 4);
		cs_pen2 = new Cursor(display, id_pen2, 6, 6);
		cs_pen3 = new Cursor(display, id_pen3, 8, 8);
		cs_pen4 = new Cursor(display, id_pen4, 11, 11);
		//橡皮手势
		ImageData id_rubber0 =new ImageData("cursor\\rubber_7.png");
		ImageData id_rubber1 =new ImageData("cursor\\rubber_11.png");
		ImageData id_rubber2 =new ImageData("cursor\\rubber_15.png");
		ImageData id_rubber3 =new ImageData("cursor\\rubber_19.png");
		ImageData id_rubber4 =new ImageData("cursor\\rubber_24.png");
		cs_rubber0 = new Cursor(display, id_rubber0, 2, 2);
		cs_rubber1 = new Cursor(display, id_rubber1, 4, 4);
		cs_rubber2 = new Cursor(display, id_rubber2, 6, 6);
		cs_rubber3 = new Cursor(display, id_rubber3, 8, 8);
		cs_rubber4 = new Cursor(display, id_rubber4, 11, 11);
		
		//填充光标
		ImageData id_fill =new ImageData("cursor\\cs_fill_15.png");
		cs_fill = new Cursor(display, id_fill, 0, 0);
		//鼠标手势***结束*************************************************************************************
		
		readTxt();//预读文档
		
		createContents();
	}
	/**
	 * Open the window.
	 */
	
	public void open() {
		shlGms.open();
		shlGms.layout();
		while (!shlGms.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		
	}

	/**
	 * Create contents of the window.
	 * @wbp.parser.entryPoint
	 */
	protected void createContents() {
		shlGms = new Shell(SWT.CLOSE | SWT.MIN);
		shlGms.setBackgroundImage(SWTResourceManager.getImage(GMS.class, "/img/back_1200_675.jpg"));
		shlGms.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		shlGms.setImage(SWTResourceManager.getImage(GMS.class, "/img/GMS.png"));
		shlGms.setLocation(20, 20);
		shlGms.setSize(1200, 675);
		shlGms.setText("GMS-房间ID：" + roomID);
		shlGms.setLayout(null);
		
		shlGms.addShellListener(new ShellAdapter() {
			@Override
			public void shellClosed(ShellEvent e) {
				e.doit = false;
				if(download != null){
					download.shell.dispose();
				}
				SlowlyDisappear(shlGms, 675, shlGms.getLocation().y);//慢慢关闭
			}
		});
		
		shlGms.addDisposeListener(new DisposeListener() {
			public void widgetDisposed(DisposeEvent arg0) {
				saveTxt();//保存txt文档的操作
				//界面其他组建消除***********************************************************************
				for(int i=0;i < cu.length;i++){
					cu[i].cuDispose();
				}
				
				/*for(int i=0;i < ld.length;i++){
					ld[i].ldDispose();
				}*/
				//界面其他组建消除***结束******************************************************************
				
				RMM.setOpen(false);
				RMM.exit();
				IAC.stopAudioSession();//关闭线程的操作
				dpc.exite();
				tcc.end();
				
			}
		});
			
		//聊天窗口
		composite_chat = new Composite(shlGms, SWT.BORDER);
		composite_chat.setBounds(8, 10, 240, 630);
		composite_chat.setBackgroundMode(SWT.INDETERMINATE);
		
		lbl_powerInfo = new Label(composite_chat, SWT.NONE);
		lbl_powerInfo.setAlignment(SWT.CENTER);
		lbl_powerInfo.setBounds(10, 111, 216, 17);
		lbl_powerInfo.setVisible(false);
		
		final Label lbl_chatlogs = new Label(composite_chat, SWT.NONE);
		lbl_chatlogs.setText("已经没有更多的聊天记录了");
		lbl_chatlogs.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		lbl_chatlogs.setAlignment(SWT.CENTER);
		lbl_chatlogs.setBounds(13, 390, 192, 17);
		lbl_chatlogs.setVisible(false);
		
		final Scale scale_mic = new Scale(composite_chat, SWT.VERTICAL);
		scale_mic.setSelection((int) (100-SoundProcessor.DEFAULT_MIC_VOLUME*100));
		scale_mic.setBounds(16, 349, 38, 88);
		scale_mic.setVisible(false);
		
		final Scale scale_vol = new Scale(composite_chat, SWT.VERTICAL);	
		scale_vol.setSelection((int) (100-AudioMixerModel.DEFAULT_VOLUME_PERCENT*100));
		scale_vol.setBounds(60, 349, 38, 88);
		scale_vol.setVisible(false);
		
		
		//显示音量文本框
		progressBar = new ProgressBar(composite_chat, SWT.NONE);
		progressBar.setForeground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		progressBar.setState(SWT.PAUSED);
		progressBar.setMaximum(AudioCaptureModel.MAX_DB);
		progressBar.setSelection(0);
		progressBar.setBounds(10, 490, 216, 8);
		
		
		//用户头像1*****************************************************************************************
		cu[0] = new CompositeUser(10, 5, composite_chat, cs_hand);	
		if(userList[0] != null){
			cu[0].setVis();
			cu[0].setName(userList[0].getName());
			//cu[0].setBossHead();
		}
		else{
			cu[0].setNone();
		}
		//*********************************************************************************************
		
		//用户头像2***************************************************************************************
		cu[1] = new CompositeUser(67, 5, composite_chat, cs_hand);
		if(userList[1] != null){
			cu[1].setVis();
			cu[1].setName(userList[1].getName());
		}
		else{
			cu[1].setNone();
		}
		//*********************************************************************************************
		
		//用户头像3**************************************************************************************
		cu[2] = new CompositeUser(124, 5, composite_chat, cs_hand);
		if(userList[2] != null){
			cu[2].setVis();
			cu[2].setName(userList[2].getName());
		}
		else{
			cu[2].setNone();
		}
		//**********************************************************************************************
		
		//用户头像4**************************************************************************************
		cu[3] = new CompositeUser(181, 5, composite_chat, cs_hand);
		if(userList[3] != null){
			cu[3].setVis();
			cu[3].setName(userList[3].getName());
		}
		else{
			cu[3].setNone();
		}
		//**********************************************************************************************
		
		//用户头像5**************************************************************************************
		cu[4] = new CompositeUser(10, 56, composite_chat, cs_hand);
		if(userList[4] != null){
			cu[4].setVis();
			cu[4].setName(userList[4].getName());
		}
		else{
			cu[4].setNone();
		}
		//**********************************************************************************************
		
		//用户头像6**************************************************************************************
		cu[5] = new CompositeUser(67, 56, composite_chat, cs_hand);
		if(userList[5] != null){
			cu[5].setVis();
			cu[5].setName(userList[5].getName());
		}
		else{
			cu[5].setNone();
		}
		//**********************************************************************************************
		
		//用户头像7**************************************************************************************		
		cu[6] = new CompositeUser(124, 56, composite_chat, cs_hand);
		if(userList[6] != null){
			cu[6].setVis();
			cu[6].setName(userList[6].getName());
		}
		else{
			cu[6].setNone();
		}
		//**********************************************************************************************
		
		//用户头像8**************************************************************************************
		cu[7] = new CompositeUser(181, 56, composite_chat, cs_hand);
		if(userList[7] != null){
			cu[7].setVis();
			cu[7].setName(userList[7].getName());
		}
		else{
			cu[7].setNone();
		}
		//**********************************************************************************************
		
		//用户头像点击响应*********************************************************************************
		for(int i=0;i < cu.length;i++){
			final int count = i;
			cu[count].getHead().addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDown(MouseEvent e) {
					if(!cu[count].isNone()){
						if(userFocusIndex >= 0){
							boolean isUser = ClientUserInformations.getInstance().getIp().equals(userList[count].getIp());
							if(hasPen && !isUser){
								cu[userFocusIndex].lostFocus();
								userFocusIndex = count;
								cu[userFocusIndex].setFocus();
								dpc.passAuthority(userList[userFocusIndex].getIp());
								hasPen = false;
								btn_pencil.setImage(SWTResourceManager.getImage(GMS.class, "/img/pencil_34.png"));
							}
						}
						else{
							PowerInfoThread pt = new PowerInfoThread("现在是抢画笔时间");
							pt.start();
						}
					}			
				}
			});
				
		}
		//用户头像点击响应***结束******************************************************************************
		
		//音量大小面板
		final Label label_mic = new Label(composite_chat, SWT.NONE);
		label_mic.setToolTipText("禁音");
		label_mic.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseDown(MouseEvent e) {	
				scale_mic.setSelection(100);
				label_mic.setText("");
				label_mic.setImage(SWTResourceManager.getImage(GMS.class, "/img/block_15.png"));
				tltm_mic.setImage(SWTResourceManager.getImage(GMS.class, "/img/麦克风_禁音_30.png"));
				IAC.setMicroVolume(0);
			}
		});
		label_mic.setAlignment(SWT.CENTER);
		label_mic.setBounds(16, 333, 38, 16);
		label_mic.setText(""+(100-scale_mic.getSelection()));
		label_mic.setVisible(false);
		label_mic.setCursor(cs_hand);
		
		final Label label_vol = new Label(composite_chat, SWT.NONE);
		label_vol.setToolTipText("禁音");
		label_vol.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseDown(MouseEvent e) {
				label_vol.setText("");
				scale_vol.setSelection(100);
				label_vol.setImage(SWTResourceManager.getImage(GMS.class, "/img/block_15.png"));
				tltm_vol.setImage(SWTResourceManager.getImage(GMS.class, "/img/音响_禁音_30.png"));
				IAC.setVolume(0);
			}
		});
		label_vol.setAlignment(SWT.CENTER);
		label_vol.setBounds(60, 333, 38, 16);
		label_vol.setText(""+(100-scale_vol.getSelection()));
		label_vol.setVisible(false);
		label_vol.setCursor(cs_hand);
		
		
		//聊天面板工具栏
		ToolBar toolBar = new ToolBar(composite_chat, SWT.FLAT | SWT.RIGHT);
		toolBar.setBounds(10, 444, 216, 40);
		
		ToolItem toolItem_sep0 = new ToolItem(toolBar, SWT.SEPARATOR);
		
		tltm_mic = new ToolItem(toolBar, SWT.CHECK);
		tltm_mic.setImage(SWTResourceManager.getImage(GMS.class, "/img/麦克风_30.png"));
		tltm_mic.setToolTipText("麦克风音量");
		tltm_mic.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				if(tltm_mic.getSelection()){
					scale_mic.setVisible(true);
					label_mic.setVisible(true);
				}
				else{
					scale_mic.setVisible(false);
					label_mic.setVisible(false);
				}
			}
		});
		
		
		ToolItem toolItem_sep1 = new ToolItem(toolBar, SWT.SEPARATOR);
		
		tltm_vol = new ToolItem(toolBar, SWT.CHECK);
		tltm_vol.setImage(SWTResourceManager.getImage(GMS.class, "/img/音响_30.png"));
		tltm_vol.setToolTipText("喇叭/耳机音量");
		tltm_vol.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				if(tltm_vol.getSelection()){
					scale_vol.setVisible(true);
					label_vol.setVisible(true);
				}
				else{
					scale_vol.setVisible(false);
					label_vol.setVisible(false);
				}
			}
		});
		
		
		ToolItem toolItem_sep2 = new ToolItem(toolBar, SWT.SEPARATOR);
		
		tltm_chatlogs = new ToolItem(toolBar, SWT.NONE);
		tltm_chatlogs.setImage(SWTResourceManager.getImage(GMS.class, "/img/聊天记录30.png"));
		tltm_chatlogs.setToolTipText("\u804A\u5929\u8BB0\u5F55");
		tltm_chatlogs.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				//隐藏俩音量窗口**************************************
				scale_mic.setVisible(false);
				scale_vol.setVisible(false);
				tltm_mic.setSelection(false);
				tltm_vol.setSelection(false);
				label_mic.setVisible(false);
				label_vol.setVisible(false);
				//隐藏俩音量窗口***结束***********************************
				
				if(text_chat.isVisible()){
					text_chat.setVisible(false);
					
					btn_addChatlogs.setVisible(true);
					btn_la.setVisible(true);
					btn_ne.setVisible(true);
					lbl_chatPage.setVisible(true);
					
					text_chatlogs.setVisible(true);	
					btn_addChatlogs.setVisible(true);
					tltm_chatlogs.setImage(SWTResourceManager.getImage(GMS.class, "/img/chat_new_30.png"));
					tltm_chatlogs.setToolTipText("聊天窗口");
					
					tcc.viewMessageRocored();
					addChatlogs();
					
				}
				else{
					text_chat.setVisible(true);
					
					btn_addChatlogs.setVisible(false);
					btn_la.setVisible(false);
					btn_ne.setVisible(false);
					lbl_chatPage.setVisible(false);
					
					text_chatlogs.setVisible(false);
					btn_addChatlogs.setVisible(false);
					tltm_chatlogs.setImage(SWTResourceManager.getImage(GMS.class, "/img/聊天记录30.png"));
					tltm_chatlogs.setToolTipText("聊天记录");
					text_chatlogs.setText("");
					currentChatlogsP = 0;
					totalChatlogsP = 0;
					for(int i=0;i<chatlogs.length;i++){
						chatlogs[i] = null;
					}
				}
			}
		});
		
		
		ToolItem toolItem_sep3 = new ToolItem(toolBar, SWT.SEPARATOR);
		//************************************************************************************
		
		
		//mic，vol音量刻度响应******************************************************************		
		scale_mic.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {				
				if(scale_mic.getSelection() == 100){
					label_mic.setText("");
					label_mic.setImage(SWTResourceManager.getImage(GMS.class, "/img/block_15.png"));
					tltm_mic.setImage(SWTResourceManager.getImage(GMS.class, "/img/麦克风_禁音_30.png"));
				}
				else{			
					tltm_mic.setImage(SWTResourceManager.getImage(GMS.class, "/img/麦克风_30.png"));
				}
				IAC.setMicroVolume((float)((100-scale_mic.getSelection())/100.0));
			}
			@Override
			public void mouseDown(MouseEvent e) {
				label_mic.setText(""+(100-scale_mic.getSelection()));
			}
		});
		scale_mic.addMouseMoveListener(new MouseMoveListener() {
			public void mouseMove(MouseEvent e) {
				if(scale_mic.getSelection() != 100){
					label_mic.setText(""+(100-scale_mic.getSelection()));					
				}
				IAC.setMicroVolume((float)((100-scale_mic.getSelection())/100.0));
			}
		});
		
		scale_vol.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {				
				if(scale_vol.getSelection() == 100){
					label_vol.setText("");
					label_vol.setImage(SWTResourceManager.getImage(GMS.class, "/img/block_15.png"));
					tltm_vol.setImage(SWTResourceManager.getImage(GMS.class, "/img/音响_禁音_30.png"));
				}
				else{		
					tltm_vol.setImage(SWTResourceManager.getImage(GMS.class, "/img/音响_30.png"));
				}
				
				IAC.setVolume((float)((100-scale_vol.getSelection())/100.0));
			}
			@Override
			public void mouseDown(MouseEvent e) {
				label_vol.setText(""+(100-scale_vol.getSelection()));
			}
		});	
		scale_vol.addMouseMoveListener(new MouseMoveListener() {
			public void mouseMove(MouseEvent e) {
				if(scale_vol.getSelection() != 100){
					label_vol.setText(""+(100-scale_vol.getSelection()));
				}
				IAC.setVolume((float)((100-scale_vol.getSelection())/100.0));
			}
		});
		
		btn_addChatlogs = new Button(composite_chat, SWT.NONE);
		btn_addChatlogs.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				boolean b = addChatlogs();//是否有聊天记录
				if(!b){
					lbl_chatlogs.setVisible(true);
					BackgroundThread bt = new BackgroundThread(lbl_chatlogs);
					bt.start();
				}
			}
		});
		btn_addChatlogs.setText("更多记录");
		btn_addChatlogs.setBounds(166, 418, 60, 20);
		btn_addChatlogs.setVisible(false);
		
		btn_la = new Button(composite_chat, SWT.NONE);
		btn_la.setToolTipText("上一页");
		btn_la.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				if(currentChatlogsP != 1){
					currentChatlogsP --;
					lbl_chatPage.setText(currentChatlogsP + "/" + totalChatlogsP);
					text_chatlogs.setText(chatlogs[currentChatlogsP-1]);
				}
				
			}
		});
		btn_la.setImage(SWTResourceManager.getImage(GMS.class, "/img/上一个_19.png"));
		btn_la.setBounds(10, 418, 20, 20);
		btn_la.setVisible(false);
		
		lbl_chatPage = new Label(composite_chat, SWT.NONE);
		lbl_chatPage.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		lbl_chatPage.setAlignment(SWT.CENTER);
		lbl_chatPage.setBounds(40, 420, 50, 17);
		lbl_chatPage.setVisible(false);
		
		btn_ne = new Button(composite_chat, SWT.NONE);
		btn_ne.setToolTipText("下一页");
		btn_ne.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				if(currentChatlogsP != totalChatlogsP){
					currentChatlogsP ++;
					lbl_chatPage.setText(currentChatlogsP + "/" + totalChatlogsP);
					text_chatlogs.setText(chatlogs[currentChatlogsP-1]);
				}
				
			}
		});
		btn_ne.setImage(SWTResourceManager.getImage(GMS.class, "/img/下一个_19.png"));
		btn_ne.setBounds(100, 418, 20, 20);
		btn_ne.setVisible(false);
		
		//mic，vol音量刻度响应***结束*******************************************************************************
		
		
		
		//显示聊天内同文本框
		text_chat = new StyledText(composite_chat, SWT.BORDER | SWT.READ_ONLY | SWT.WRAP | SWT.V_SCROLL | SWT.MULTI);
		text_chat.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		text_chat.setBounds(10, 111, 216, 327);
		text_chat.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				scale_mic.setVisible(false);
				scale_vol.setVisible(false);
				tltm_mic.setSelection(false);
				tltm_vol.setSelection(false);
				label_mic.setVisible(false);
				label_vol.setVisible(false);
			}
		});
		
		
		//消息记录
		text_chatlogs = new Text(composite_chat, SWT.BORDER | SWT.READ_ONLY | SWT.WRAP | SWT.V_SCROLL | SWT.MULTI);
		text_chatlogs.setBounds(10, 111, 216, 300);
		text_chatlogs.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				scale_mic.setVisible(false);
				scale_vol.setVisible(false);
				tltm_mic.setSelection(false);
				tltm_vol.setSelection(false);
				label_mic.setVisible(false);
				label_vol.setVisible(false);
			}
		});
		text_chatlogs.setVisible(false);
		
		final Label lbl_warning = new Label(composite_chat, SWT.NONE);
		lbl_warning.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		lbl_warning.setAlignment(SWT.CENTER);
		lbl_warning.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		lbl_warning.setText("发送内容不能为空!");
		lbl_warning.setBounds(20, 565, 180, 20);
		lbl_warning.setVisible(false);
		
		
		//输入文本框
		text_send = new StyledText(composite_chat, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
		text_send.addKeyListener(new KeyAdapter() {
			@Override
			public void keyPressed(KeyEvent e) {
				if(e.keyCode == 13 && e.stateMask == SWT.CTRL){
					String sendMsg = text_send.getText().substring(0,text_send.getText().length()-2);
					if(sendMsg.equals("")){
						lbl_warning.setVisible(true);
						BackgroundThread bt = new BackgroundThread(lbl_warning);
						bt.start();
					}
					else{
						/*long timemillis = System.currentTimeMillis();   
						//转换日期显示格式   
						SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");
						text_chat.append(ClientUserInformations.getInstance().getUserName() + "  " + df.format(new Date(timemillis)) + '\n');
						text_chat.append(text_send.getText() + '\n');*/
						try {
							tcc.sendMessage(sendMsg);
						} catch (IOException e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						}
					}
					text_send.setText("");
				}
			}
		});
		text_send.setTextLimit(100);
		text_send.setBounds(10, 504, 216, 85);
		
		text_send.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseDown(MouseEvent e) {
				lbl_warning.setVisible(false);
				
				scale_mic.setVisible(false);
				scale_vol.setVisible(false);
				tltm_mic.setSelection(false);
				tltm_vol.setSelection(false);
				label_mic.setVisible(false);
				label_vol.setVisible(false);
			}
		});
		
		
		//发送按钮
		Button button_send = new Button(composite_chat, SWT.NONE);
		button_send.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				if(text_send.getText().equals("")){
					lbl_warning.setVisible(true);
					BackgroundThread bt = new BackgroundThread(lbl_warning);
					bt.start();
				}
				else{
					/*long timemillis = System.currentTimeMillis();   
					//转换日期显示格式   
					SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");
					text_chat.append(ClientUserInformations.getInstance().getUserName() + "  " + df.format(new Date(timemillis)) + '\n');
					text_chat.append(text_send.getText() + '\n');*/
					try {
						tcc.sendMessage(text_send.getText());
					} catch (IOException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
					text_send.setText("");
				}
			}
		});
		button_send.setToolTipText("\u70B9\u51FB\u53D1\u9001\u6D88\u606F");
		button_send.setBounds(146, 595, 80, 27);
		button_send.setText("\u53D1\u9001");
		
		final Button button_save = new Button(shlGms, SWT.NONE);
		button_save.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				FileDialog fd = new FileDialog(shlGms,SWT.SAVE);
				fd.setFilterExtensions(new String[]{"(JPEG)*.jpg"});
				fd.open();
				dpc.save(fd.getFilterPath()+"\\"+fd.getFileName());
			}
		});
		button_save.setImage(SWTResourceManager.getImage(GMS.class, "/img/保存_32.png"));
		button_save.setLocation(302, 10);
		button_save.setSize(40, 40);
		button_save.setToolTipText("\u4FDD\u5B58\u9762\u677F");
		button_save.addMouseTrackListener(new MouseTrackAdapter() {
			@Override
			public void mouseEnter(MouseEvent e) {
				button_save.forceFocus();
			}
		});
		
		
		
		//文本窗口******************************************************************************************
		final Composite composite_text = new Composite(shlGms, SWT.BORDER);
		composite_text.setBackground(SWTResourceManager.getColor(255, 255, 204));
		//composite_text.setBackgroundImage(SWTResourceManager.getImage("D:\\pictures\\snow_300_580.jpg"));
		composite_text.setLocation(895, 60);
		composite_text.setSize(0, 580);
		composite_text.setBackgroundMode(SWT.INHERIT_FORCE);
		
		Button btn_push = new Button(composite_text, SWT.NONE);
		btn_push.setToolTipText("点击隐藏文本栏");
		btn_push.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				toRightSlowlyDisappear(composite_text, 300, 895);
			}
		});
		btn_push.setBounds(0, 276, 14, 27);
		btn_push.setText(">");
		
		final Label lbl_remind = new Label(composite_text, SWT.NONE);
		lbl_remind.setAlignment(SWT.CENTER);
		lbl_remind.setBounds(25, 527, 260, 20);
		lbl_remind.setVisible(false);
		
		text = new StyledText(composite_text, SWT.WRAP | SWT.V_SCROLL | SWT.MULTI);
		text.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseDown(MouseEvent e) {
				lbl_remind.setVisible(false);
			}
		});
		text.setText(textString[currentPage - 1]);
		text.setLocation(18, 0);
		text.setSize(285, 540);
		
		final Label lbl_page = new Label(composite_text, SWT.NONE);
		lbl_page.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NORMAL));
		lbl_page.setAlignment(SWT.CENTER);
		lbl_page.setText(currentPage + "/" + totalPage);
		lbl_page.setBounds(134, 547, 41, 25);
		
		Button btn_delT = new Button(composite_text, SWT.NONE);
		btn_delT.setToolTipText("删除当前文档");
		btn_delT.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				lbl_remind.setVisible(false);
				if(totalPage == 1){
					if(text.getText().equals("")){
						text.forceFocus();
						lbl_remind.setText("文本已全部删除");
						lbl_remind.setVisible(true);
						BackgroundThread bt = new BackgroundThread(lbl_remind);
						bt.start();
					}
					else{
						text.setText("");
					}				
				}
				else{
					for(int i=currentPage-1;i < totalPage-1;i++){
						textString[i] = textString[i+1];
					}
					
					if(currentPage == totalPage){
						currentPage --;
					}
					totalPage --;
					text.setText(textString[currentPage - 1]);
					
					lbl_page.setText(currentPage + "/" + totalPage);
				}
				
			}
		});
		btn_delT.setImage(SWTResourceManager.getImage(GMS.class, "/img/delete_23.png"));
		btn_delT.setBounds(20, 547, 25, 25);
		
		Button btn_first = new Button(composite_text, SWT.NONE);
		btn_first.setToolTipText("首页");
		btn_first.setImage(SWTResourceManager.getImage(GMS.class, "/img/rewindtostart_21.png"));
		btn_first.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				lbl_remind.setVisible(false);
				if(currentPage == 1){
					lbl_remind.setText("已经是第一页了");
					lbl_remind.setVisible(true);
					BackgroundThread bt = new BackgroundThread(lbl_remind);
					bt.start();
				}
				else{
					textString[currentPage - 1] = text.getText();
					currentPage = 1;
					text.setText(textString[currentPage - 1]);
					lbl_page.setText(currentPage + "/" + totalPage);				
				}
			}
		});
		btn_first.setBounds(75, 547, 25, 25);
		
		Button btn_lastT = new Button(composite_text, SWT.NONE);
		btn_lastT.setToolTipText("上一页");
		btn_lastT.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				lbl_remind.setVisible(false);
				if(currentPage == 1){
					lbl_remind.setText("已经是第一页了");
					lbl_remind.setVisible(true);
					BackgroundThread bt = new BackgroundThread(lbl_remind);
					bt.start();
				}
				else{
					textString[currentPage - 1] = text.getText();
					currentPage --;
					text.setText(textString[currentPage - 1]);
					lbl_page.setText(currentPage + "/" + totalPage);				
				}
			}
		});
		btn_lastT.setImage(SWTResourceManager.getImage(GMS.class, "/img/上一个_24.png"));
		btn_lastT.setBounds(102, 547, 25, 25);
		
		Button btn_nextT = new Button(composite_text, SWT.NONE);
		btn_nextT.setToolTipText("下一页");
		btn_nextT.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				lbl_remind.setVisible(false);
				if(currentPage == totalPage){
					lbl_remind.setText("已经是最后一页了");
					lbl_remind.setVisible(true);
					BackgroundThread bt = new BackgroundThread(lbl_remind);
					bt.start();
				}
				else{
					textString[currentPage - 1] = text.getText();
					currentPage ++;
					text.setText(textString[currentPage - 1]);
					lbl_page.setText(currentPage + "/" + totalPage);
				}
			}
		});
		btn_nextT.setImage(SWTResourceManager.getImage(GMS.class, "/img/下一个_24.png"));
		btn_nextT.setBounds(181, 547, 25, 25);
		
		Button btn_endl = new Button(composite_text, SWT.NONE);
		btn_endl.setToolTipText("末页");
		btn_endl.setImage(SWTResourceManager.getImage(GMS.class, "/img/forwardtoend_21.png"));
		btn_endl.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				lbl_remind.setVisible(false);
				if(currentPage == totalPage){
					lbl_remind.setText("已经是最后一页了");
					lbl_remind.setVisible(true);
					BackgroundThread bt = new BackgroundThread(lbl_remind);
					bt.start();
				}
				else{
					textString[currentPage - 1] = text.getText();
					currentPage = totalPage;
					text.setText(textString[currentPage - 1]);
					lbl_page.setText(currentPage + "/" + totalPage);
				}
			}
		});
		btn_endl.setBounds(208, 547, 25, 25);
		
		Button btn_addT = new Button(composite_text, SWT.NONE);
		btn_addT.setToolTipText("新文档");
		btn_addT.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				lbl_remind.setVisible(false);
				if(totalPage == MAX_TXT){
					lbl_remind.setText("已经不能添加文本了");
					lbl_remind.setVisible(true);
					BackgroundThread bt = new BackgroundThread(lbl_remind);
					bt.start();
				}
				else{
					text.forceFocus();
					textString[currentPage - 1] = text.getText();
					text.setText("");				
					for(int i=totalPage-1;i >= currentPage-1;i--){
						textString[i+1] = textString[i];
					}
					totalPage ++;
					currentPage ++;
					lbl_page.setText(currentPage + "/" + totalPage);
				}
				
			}
		});
		btn_addT.setImage(SWTResourceManager.getImage(GMS.class, "/img/plus_加23.png"));
		btn_addT.setBounds(263, 547, 25, 25);
		//文本窗口***结束******************************************************************************
		
		//工具窗口***********************************************************************************
		final Composite composite_tool = new Composite(shlGms, SWT.BORDER);
		composite_tool.setBounds(256, 50, 40, 456);
		composite_tool.setVisible(false);	
		
		//工具按钮
		final Button btn_tool = new Button(shlGms, SWT.FLAT | SWT.TOGGLE | SWT.CENTER);
		btn_tool.setImage(SWTResourceManager.getImage(GMS.class, "/img/工具栏_33_32.png"));
		btn_tool.setToolTipText("工具栏");
		btn_tool.setBounds(256, 10, 40, 40);
		btn_tool.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				if(btn_tool.getSelection()){
					composite_tool.setVisible(true);
				}
				else{
					composite_tool.setVisible(false);
				}
			}
		});
		composite_tool.setLayout(null);
		
		final Button button_text = new Button(composite_tool, SWT.NONE);
		button_text.setImage(SWTResourceManager.getImage(GMS.class, "/img/text_30.png"));
		button_text.setToolTipText("插入文本");
		button_text.setBounds(0, 54, 36, 36);
		button_text.addMouseTrackListener(new MouseTrackAdapter() {
			@Override
			public void mouseEnter(MouseEvent e) {
				button_text.forceFocus();
			}
		});
		button_text.addMouseListener(new MouseAdapter(){
			public void mouseUp(MouseEvent e){
				if(!hasPen){
					return;
				}
				dpc.setTool(6);
				dpc.setCursor(1);
				tool =6;
				drawPanel.setCursor(cs_arrow);
			}
		});
		
		final Button button_picture = new Button(composite_tool, SWT.NONE);
		button_picture.setImage(SWTResourceManager.getImage(GMS.class, "/img/img_30.png"));
		button_picture.setToolTipText("插入图片");
		button_picture.setBounds(0, 90, 36, 36);
		//----------------------------------wbr_picture-----------------------------------//
		button_picture.addMouseTrackListener(new MouseTrackAdapter() {
			@Override
			public void mouseEnter(MouseEvent e) {
				button_picture.forceFocus();
			}
		});
		button_picture.addMouseListener(new MouseAdapter(){
			public void mouseUp(MouseEvent e){
				if(!hasPen){
					return;
				}
				FileDialog fd = new FileDialog(shlGms ,SWT.OPEN);
				fd.setFilterExtensions(new String[]{"*.jpg(JPEG)"});
				fd.open();
				dpc.addPicture(fd.getFilterPath() + "/" + fd.getFileName()) ;
			}
		});
		//----------------------------------wbr_picture-----------------------------------//
				
		
		Label label_sep0 = new Label(composite_tool, SWT.SEPARATOR | SWT.HORIZONTAL);
		label_sep0.setBackground(SWTResourceManager.getColor(SWT.COLOR_RED));
		label_sep0.setBounds(0, 133, 38, 3);		
		
			
		final Button button_pen = new Button(composite_tool, SWT.NONE);
		button_pen.setImage(SWTResourceManager.getImage(GMS.class, "/img/pencil_30.png"));
		button_pen.setToolTipText("画笔");
		button_pen.setBounds(0, 144, 36, 36);
		button_pen.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				if(!hasPen){
					return;
				}
				switch (size){
				case 5:
					drawPanel.setCursor(cs_pen0);
					break;
				case 10:
					drawPanel.setCursor(cs_pen1);
					break;
				case 15:
					drawPanel.setCursor(cs_pen2);
					break;
				case 20:
					drawPanel.setCursor(cs_pen3);
					break;
				case 25:
					drawPanel.setCursor(cs_pen4);
					break;
				default:
					drawPanel.setCursor(cs_pen0);
					break;
				}	
				
			}
		});
		
		button_pen.addMouseTrackListener(new MouseTrackAdapter() {
			@Override
			public void mouseEnter(MouseEvent e) {
				button_pen.forceFocus();
			}
		});
		button_pen.addMouseListener(new MouseAdapter(){
			public void mouseUp(MouseEvent e){
				if(!hasPen){
					return;
				}
				dpc.setTool(1);
				dpc.setCursor(1);
				tool =1;
				
			}
		});
		//注释掉填充
		/*final Button button_fill = new Button(composite_tool, SWT.NONE);
		button_fill.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				if(!hasPen){
					return;
				}
				drawPanel.setCursor(cs_fill);
			}
		});
		button_fill.setImage(SWTResourceManager.getImage(GMS.class, "/img/fill_30.jpg"));
		button_fill.setToolTipText("填充");
		button_fill.setBounds(0, 168, 36, 36);
		button_fill.addMouseTrackListener(new MouseTrackAdapter() {
			@Override
			public void mouseEnter(MouseEvent e) {
				button_fill.forceFocus();
			}
		});
		button_fill.addMouseListener(new MouseAdapter(){
			public void mouseUp(MouseEvent e){
				if(!hasPen){
					return;
				}
				dpc.setTool(7);
				dpc.setCursor(1);
				tool =7;
			}
		});*/
		
		final Button button_rubber = new Button(composite_tool, SWT.NONE);
		button_rubber.setImage(SWTResourceManager.getImage(GMS.class, "/img/rubber_30.png"));
		button_rubber.setToolTipText("橡皮");
		button_rubber.setBounds(0, 180, 36, 36);
		button_rubber.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				if(!hasPen){
					return;
				}
				switch (size){
				case 5:
					drawPanel.setCursor(cs_rubber0);
					break;
				case 10:
					drawPanel.setCursor(cs_rubber1);
					break;
				case 15:
					drawPanel.setCursor(cs_rubber2);
					break;
				case 20:
					drawPanel.setCursor(cs_rubber3);
					break;
				case 25:
					drawPanel.setCursor(cs_rubber4);
					break;
				default:
					drawPanel.setCursor(cs_rubber0);
					break;
				}
			}
		});
		
		button_rubber.addMouseTrackListener(new MouseTrackAdapter() {
			@Override
			public void mouseEnter(MouseEvent e) {
				button_rubber.forceFocus();
			}
		});
		button_rubber.addMouseListener(new MouseAdapter(){
			public void mouseUp(MouseEvent e){
				if(!hasPen){
					return;
				}
				dpc.setTool(8);
				dpc.setCursor(1);
				tool =8;
			}
		});
		
		final Button button_circle = new Button(composite_tool, SWT.NONE);
		button_circle.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				if(!hasPen){
					return;
				}
				drawPanel.setCursor(cs_cross);
			}
		});
		button_circle.setImage(SWTResourceManager.getImage(GMS.class, "/img/circle_30.jpg"));
		button_circle.setToolTipText("圆形");
		button_circle.setBounds(0, 216, 36, 36);
		button_circle.addMouseTrackListener(new MouseTrackAdapter() {
			@Override
			public void mouseEnter(MouseEvent e) {
				button_circle.forceFocus();
			}
		});
		button_circle.addMouseListener(new MouseAdapter(){
			public void mouseUp(MouseEvent e){
				if(!hasPen){
					return;
				}
				dpc.setTool(3);
				dpc.setCursor(1);
				tool =3;
			}
		});
		
		final Button button_rectangle = new Button(composite_tool, SWT.NONE);
		button_rectangle.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				if(!hasPen){
					return;
				}
				drawPanel.setCursor(cs_cross);
			}
		});
		button_rectangle.setImage(SWTResourceManager.getImage(GMS.class, "/img/rect_30.jpg"));
		button_rectangle.setToolTipText("矩形");
		button_rectangle.setBounds(0, 252, 36, 36);
		button_rectangle.addMouseTrackListener(new MouseTrackAdapter() {
			@Override
			public void mouseEnter(MouseEvent e) {
				button_rectangle.forceFocus();
			}
		});
		button_rectangle.addMouseListener(new MouseAdapter(){
			public void mouseUp(MouseEvent e){
				if(!hasPen){
					return;
				}
				dpc.setTool(4);
				dpc.setCursor(1);
				tool = 4;
			}
		});
		
		final Button button_straight = new Button(composite_tool, SWT.NONE);
		button_straight.setImage(SWTResourceManager.getImage(GMS.class, "/img/直线_30.jpg"));
		button_straight.setToolTipText("直线");
		button_straight.setBounds(0, 288, 36, 36);
		button_straight.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				if(!hasPen){
					return;
				}
				drawPanel.setCursor(cs_cross);
			}
		});
		
		button_straight.addMouseTrackListener(new MouseTrackAdapter() {
			@Override
			public void mouseEnter(MouseEvent e) {
				button_straight.forceFocus();
			}
		});
		button_straight.addMouseListener(new MouseAdapter(){
			public void mouseUp(MouseEvent e){
				if(!hasPen){
					return;
				}
				dpc.setTool(2);
				dpc.setCursor(1);
				tool =2;
			}
		});
		
		Label label_sep1 = new Label(composite_tool, SWT.SEPARATOR | SWT.HORIZONTAL);
		label_sep1.setBackground(SWTResourceManager.getColor(SWT.COLOR_RED));
		label_sep1.setBounds(0, 331, 38, 3);
		
		final Button button_thin = new Button(composite_tool, SWT.NONE);
		button_thin.setToolTipText("画笔粗细");
		button_thin.setImage(SWTResourceManager.getImage(GMS.class, "/img/thin_30.jpg"));
		button_thin.setBounds(0, 342, 36, 36);
		//画笔粗细窗口响应
		button_thin.addFocusListener(new FocusAdapter() {
			@Override
			public void focusLost(FocusEvent e) {
				composite_thin.setVisible(false);
			}
		});
		button_thin.addMouseTrackListener(new MouseTrackAdapter() {
			@Override
			public void mouseEnter(MouseEvent e) {
				button_thin.forceFocus();
				composite_thin.setVisible(true);
			}
		});
		
		final Button button_dotted = new Button(composite_tool, SWT.NONE);
		button_dotted.setToolTipText("线条风格");
		button_dotted.addMouseTrackListener(new MouseTrackAdapter() {
			@Override
			public void mouseEnter(MouseEvent e) {
				button_dotted.forceFocus();
				composite_line.setVisible(true);
			}
		});
		button_dotted.addFocusListener(new FocusAdapter() {
			@Override
			public void focusLost(FocusEvent e) {
				composite_line.setVisible(false);
			}
		});
		button_dotted.setImage(SWTResourceManager.getImage(GMS.class, "/img/dotted_30.jpg"));
		button_dotted.setBounds(0, 378, 36, 36);
		
		final Button button_color = new Button(composite_tool, SWT.NONE);
		button_color.setImage(SWTResourceManager.getImage(GMS.class, "/img/color_30.png"));
		button_color.setToolTipText("颜色");
		button_color.setBounds(0, 414, 36, 36);
		//颜色窗口响应
		button_color.addFocusListener(new FocusAdapter() {
			@Override
			public void focusLost(FocusEvent e) {
				composite_color.setVisible(false);
			}
		});
		button_color.addMouseTrackListener(new MouseTrackAdapter() {
			@Override
			public void mouseEnter(MouseEvent e) {
				button_color.forceFocus();
				composite_color.setVisible(true);
			}
			
		});
		
		Label label_sep2 = new Label(composite_tool, SWT.SEPARATOR | SWT.HORIZONTAL);
		label_sep2.setBackground(SWTResourceManager.getColor(SWT.COLOR_RED));
		label_sep2.setBounds(0, 43, 38, 3);
		
		final Button button_arrow = new Button(composite_tool, SWT.TOGGLE);
		button_arrow.setImage(SWTResourceManager.getImage(GMS.class, "/img/arrow_30.png"));
		button_arrow.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				if(!hasPen){
					return;
				}
				drawPanel.setCursor(cs_arrow);
				dpc.setCursor(0);
			}
		});
		button_arrow.setToolTipText("选择");
		button_arrow.setBounds(0, 0, 36, 36);
		button_arrow.addMouseTrackListener(new MouseTrackAdapter() {
			@Override
			public void mouseEnter(MouseEvent e) {
				button_arrow.forceFocus();
			}
		});
		//工具栏窗口***结束******************************************************************************
		
		//弹出文本框按钮
		final Button btn_pop = new Button(shlGms, SWT.NONE);
		btn_pop.setToolTipText("点击弹出文本框");
		btn_pop.setBounds(1179, 336, 14, 27);
		btn_pop.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				//composite_text.setVisible(true);
				toLeftSlowly(composite_text, 300, 895);
			}
		});
		btn_pop.setText("<");
		
		//颜色窗口***********************************************************
		composite_color = new Composite(shlGms, SWT.BORDER);
		composite_color.setBounds(300, 468, 288, 34);
		composite_color.setVisible(false);
		composite_color.setLayout(null);
		//整个窗口鼠标点击弹起响应
		shlGms.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				composite_tool.setVisible(false);
				composite_color.setVisible(false);
				btn_tool.setSelection(false);
			}
		});		
		//*************************************************************
		
		//画笔窗口********************************************************
		composite_thin = new Composite(shlGms, SWT.BORDER);
		composite_thin.setBounds(300, 396, 184, 34);
		composite_thin.setVisible(false);
		//****************************************************************
		
		//直线窗口***********************************************************
		composite_line = new Composite(shlGms, SWT.BORDER);
		composite_line.setBounds(300, 432, 78, 34);
		composite_line.setVisible(false);
		//****************************************************************

		//颜色窗口按钮群**************************************************************
		final Button button_white = new Button(composite_color, SWT.NONE);
		button_white.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				color = SWTResourceManager.getColor(SWT.COLOR_WHITE);
				dpc.setColor(color);
				button_color.setImage(SWTResourceManager.getImage(GMS.class, "/img/白色_30.png"));
			}
		});
		button_white.setCursor(cs_hand);
		button_white.setToolTipText("\u767D\u8272");
		button_white.setImage(SWTResourceManager.getImage(GMS.class, "/img/白色_30.png"));
		button_white.setBounds(5, 0, 30, 30);
		
		final Button button_black = new Button(composite_color, SWT.NONE);
		button_black.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				color = SWTResourceManager.getColor(SWT.COLOR_BLACK);
				dpc.setColor(color);
				button_color.setImage(SWTResourceManager.getImage(GMS.class, "/img/黑色_30.png"));
			}
		});
		button_black.setCursor(cs_hand);
		button_black.setToolTipText("\u9ED1\u8272");
		button_black.setImage(SWTResourceManager.getImage(GMS.class, "/img/黑色_30.png"));
		button_black.setBounds(40, 0, 30, 30);
		
		final Button button_red = new Button(composite_color, SWT.NONE);
		button_red.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				color = SWTResourceManager.getColor(SWT.COLOR_RED);
				dpc.setColor(color);
				button_color.setImage(SWTResourceManager.getImage(GMS.class, "/img/红色_30.png"));
			}
		});
		button_red.setCursor(cs_hand);
		button_red.setToolTipText("\u7EA2\u8272");
		button_red.setImage(SWTResourceManager.getImage(GMS.class, "/img/红色_30.png"));
		button_red.setBounds(75, 0, 30, 30);
		
		final Button button_green = new Button(composite_color, SWT.NONE);
		button_green.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				color = SWTResourceManager.getColor(34, 139, 34);
				dpc.setColor(color);
				button_color.setImage(SWTResourceManager.getImage(GMS.class, "/img/绿色_30.png"));
			}
		});
		button_green.setCursor(cs_hand);
		button_green.setToolTipText("\u7EFF\u8272");
		button_green.setImage(SWTResourceManager.getImage(GMS.class, "/img/绿色_30.png"));
		button_green.setBounds(110, 0, 30, 30);
		
		final Button button_blue = new Button(composite_color, SWT.NONE);
		button_blue.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				color = SWTResourceManager.getColor(SWT.COLOR_BLUE);
				dpc.setColor(color);
				button_color.setImage(SWTResourceManager.getImage(GMS.class, "/img/蓝色_30.png"));
			}
		});
		button_blue.setCursor(cs_hand);
		button_blue.setToolTipText("\u84DD\u8272");
		button_blue.setImage(SWTResourceManager.getImage(GMS.class, "/img/蓝色_30.png"));
		button_blue.setBounds(145, 0, 30, 30);
		
		final Button button_yellow = new Button(composite_color, SWT.NONE);
		button_yellow.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				color = SWTResourceManager.getColor(SWT.COLOR_YELLOW);
				dpc.setColor(color);
				button_color.setImage(SWTResourceManager.getImage(GMS.class, "/img/黄色_30.png"));
			}
		});
		button_yellow.setCursor(cs_hand);
		button_yellow.setToolTipText("\u9EC4\u8272");
		button_yellow.setImage(SWTResourceManager.getImage(GMS.class, "/img/黄色_30.png"));
		button_yellow.setBounds(180, 0, 30, 30);
		
		Button button_purple = new Button(composite_color, SWT.NONE);
		button_purple.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				color = SWTResourceManager.getColor(186, 85, 211);
				dpc.setColor(color);
				button_color.setImage(SWTResourceManager.getImage(GMS.class, "/img/紫色_30.png"));
			}
		});
		button_purple.setImage(SWTResourceManager.getImage(GMS.class, "/img/紫色_30.png"));
		button_purple.setCursor(cs_hand);
		button_purple.setToolTipText("紫色");
		button_purple.setBounds(215, 0, 30, 30);
		
		Button button_brown = new Button(composite_color, SWT.NONE);
		button_brown.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				color = SWTResourceManager.getColor(233, 150, 122);
				dpc.setColor(color);
				button_color.setImage(SWTResourceManager.getImage(GMS.class, "/img/棕色_30.png"));
			}
		});
		button_brown.setImage(SWTResourceManager.getImage(GMS.class, "/img/棕色_30.png"));
		button_brown.setCursor(cs_hand);
		button_brown.setToolTipText("棕色");
		button_brown.setBounds(250, 0, 30, 30);
		//颜色窗口按钮群***结束*************************************************************************
		
		//画笔/橡皮粗细窗口按钮群*******************************************************************************
		Button button_p0 = new Button(composite_thin, SWT.NONE);
		button_p0.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				size = 5;
				dpc.setWidth(size);
				button_thin.setImage(SWTResourceManager.getImage(GMS.class, "/img/pen0_30.png"));
				if(tool == 1){
					drawPanel.setCursor(cs_pen0);
				}
				else if(tool == 8){
					drawPanel.setCursor(cs_rubber0);
				}
			}
		});
		button_p0.setCursor(cs_hand);
		button_p0.setImage(SWTResourceManager.getImage(GMS.class, "/img/pen0_30.png"));
		button_p0.setBounds(5, 0, 30, 30);
		
		Button button_p1 = new Button(composite_thin, SWT.NONE);
		button_p1.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				size = 10;
				dpc.setWidth(size);
				button_thin.setImage(SWTResourceManager.getImage(GMS.class, "/img/pen1_30.png"));
				if(tool == 1){
					drawPanel.setCursor(cs_pen1);
				}
				else if(tool == 8){
					drawPanel.setCursor(cs_rubber1);
				}
			}
		});
		button_p1.setCursor(cs_hand);
		button_p1.setImage(SWTResourceManager.getImage(GMS.class, "/img/pen1_30.png"));
		button_p1.setBounds(40, 0, 30, 30);
		
		Button button_p2 = new Button(composite_thin, SWT.NONE);
		button_p2.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				size = 15;
				dpc.setWidth(size);
				button_thin.setImage(SWTResourceManager.getImage(GMS.class, "/img/pen2_30.png"));
				if(tool == 1){
					drawPanel.setCursor(cs_pen2);
				}
				else if(tool == 8){
					drawPanel.setCursor(cs_rubber2);
				}
			}
		});
		button_p2.setCursor(cs_hand);
		button_p2.setImage(SWTResourceManager.getImage(GMS.class, "/img/pen2_30.png"));
		button_p2.setBounds(75, 0, 30, 30);
		
		Button button_p3 = new Button(composite_thin, SWT.NONE);
		button_p3.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				size = 20;
				dpc.setWidth(size);
				button_thin.setImage(SWTResourceManager.getImage(GMS.class, "/img/pen3_30.png"));
				if(tool == 1){
					drawPanel.setCursor(cs_pen3);
				}
				else if(tool == 8){
					drawPanel.setCursor(cs_rubber3);
				}
			}
		});
		button_p3.setCursor(cs_hand);
		button_p3.setImage(SWTResourceManager.getImage(GMS.class, "/img/pen3_30.png"));
		button_p3.setBounds(110, 0, 30, 30);
		
		Button button_p4 = new Button(composite_thin, SWT.NONE);
		button_p4.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				size = 25;
				dpc.setWidth(size);
				button_thin.setImage(SWTResourceManager.getImage(GMS.class, "/img/pen4_30.png"));
				if(tool == 1){
					drawPanel.setCursor(cs_pen4);
				}
				else if(tool == 8){
					drawPanel.setCursor(cs_rubber4);
				}
			}
		});
		button_p4.setCursor(cs_hand);
		button_p4.setImage(SWTResourceManager.getImage(GMS.class, "/img/pen4_30.png"));
		button_p4.setBounds(145, 0, 30, 30);
		//画笔粗细窗口按钮群***结束****************************************************************************
		
		
		//直线虚实窗口按钮群*******************************************************************************
		Button btn_dottedLine = new Button(composite_line, SWT.NONE);
		btn_dottedLine.setToolTipText("虚线");
		btn_dottedLine.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				dotted = SWT.LINE_DOT;
				dpc.setLineStyle(dotted);
				button_dotted.setImage(SWTResourceManager.getImage(GMS.class, "/img/虚线_30.jpg"));
			}
		});
		btn_dottedLine.setCursor(cs_hand);
		btn_dottedLine.setImage(SWTResourceManager.getImage(GMS.class, "/img/虚线_30.jpg"));
		btn_dottedLine.setBounds(5, 0, 30, 30);
		
		Button btn_line = new Button(composite_line, SWT.NONE);
		btn_line.setToolTipText("实线");
		btn_line.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				dotted = SWT.LINE_CUSTOM;
				dpc.setLineStyle(dotted);
				button_dotted.setImage(SWTResourceManager.getImage(GMS.class, "/img/直线_30.jpg"));
			}
		});
		btn_line.setCursor(cs_hand);
		btn_line.setImage(SWTResourceManager.getImage(GMS.class, "/img/直线_30.jpg"));
		btn_line.setBounds(40, 0, 30, 30);
		//直线虚实窗口按钮群***结束*****************************************************************************
		
		ld[0] = new Label_draw(586, 10, shlGms,cs_arrow,
				cs_hand, SWTResourceManager.getImage(GMS.class, "/img/白色_38_1.png"));
		ld[0].setNum();
		
		ld[1] = new Label_draw(632, 10, shlGms,cs_arrow,
				cs_hand, SWTResourceManager.getImage(GMS.class, "/img/白色_38_2.png"));
		
		ld[2] = new Label_draw(678, 10, shlGms,cs_arrow,
				cs_hand, SWTResourceManager.getImage(GMS.class, "/img/白色_38_3.png"));
		
		ld[3] = new Label_draw(724, 10, shlGms,cs_arrow,
				cs_hand, SWTResourceManager.getImage(GMS.class, "/img/白色_38_4.png"));
		
		ld[4] = new Label_draw(770, 10, shlGms,cs_arrow,
				cs_hand, SWTResourceManager.getImage(GMS.class, "/img/白色_38_5.png"));
		
		ld[5] = new Label_draw(816, 10, shlGms,cs_arrow,
				cs_hand, SWTResourceManager.getImage(GMS.class, "/img/白色_38_6.png"));
		
		ld[6] = new Label_draw(862, 10, shlGms,cs_arrow,
				cs_hand, SWTResourceManager.getImage(GMS.class, "/img/白色_38_7.png"));
		
		ld[focusIndex].setFocus();
		
		
		//缩略图面板的响应*************************************************************************
		for(int i=0;i < ld.length;i++){
			final int count = i;
			ld[count].getLabel().addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDown(MouseEvent e) {
					if(!hasPen){
							return;
					}
					if(!ld[count].isNone()){
						
						ld[focusIndex].lostFocus();
						focusIndex = count;
						ld[focusIndex].setFocus();
						dpc.choosePanle(focusIndex);
					}
				}
			});
		}
		//缩略图面板的响应***结束**********************************************************************
		
		
		//后退按钮
		final Button btn_last = new Button(shlGms, SWT.NONE);
		btn_last.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				if(!hasPen){
					return;
				}
				lbl_lastWarning.setVisible(false);
				lbl_NDWarning.setVisible(false);
				lbl_nextWarning.setVisible(false);
				lbl_penWarning.setVisible(false);
				
				if(focusIndex == 0){
					lbl_lastWarning.setVisible(true);
					BackgroundThread bt = new BackgroundThread(lbl_lastWarning);
					bt.start();
				}
				else{
					ld[focusIndex].lostFocus();
					focusIndex --;
					ld[focusIndex].setFocus();
					dpc.choosePanle(focusIndex);
				}
			}
		});
		btn_last.setToolTipText("上一页");
		btn_last.setImage(SWTResourceManager.getImage(GMS.class, "/img/上一个_34.png"));
		btn_last.setBounds(540, 10, 40, 40);
		
		lbl_lastWarning = new Label(shlGms, SWT.NONE);
		lbl_lastWarning.setAlignment(SWT.CENTER);
		lbl_lastWarning.setBounds(510, 60, 100, 17);
		lbl_lastWarning.setText("已经是第一页了");
		lbl_lastWarning.setVisible(false);
		
		//前进按钮
		Button btn_next = new Button(shlGms, SWT.NONE);
		btn_next.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				if(!hasPen){
					return;
				}
				lbl_lastWarning.setVisible(false);
				lbl_NDWarning.setVisible(false);
				lbl_nextWarning.setVisible(false);
				lbl_penWarning.setVisible(false);
				
				if(totalLabel == 0 || focusIndex == totalLabel-1){
					lbl_nextWarning.setVisible(true);
					BackgroundThread bt = new BackgroundThread(lbl_nextWarning);
					bt.start();
				}
				else{
					ld[focusIndex].lostFocus();
					focusIndex ++;
					ld[focusIndex].setFocus();
					dpc.choosePanle(focusIndex);
				}
			}
		});
		btn_next.setToolTipText("下一页");
		btn_next.setImage(SWTResourceManager.getImage(GMS.class, "/img/下一个_34.png"));
		btn_next.setBounds(908, 10, 40, 40);
		
		lbl_nextWarning = new Label(shlGms, SWT.NONE);
		lbl_nextWarning.setAlignment(SWT.CENTER);
		lbl_nextWarning.setBounds(878, 60, 100, 17);
		lbl_nextWarning.setText("已经是最后一页了");
		lbl_nextWarning.setVisible(false);
		
		btn_pencil = new Button(shlGms, SWT.NONE);		
		btn_pencil.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				if(hasPen){
					btn_pencil.setImage(SWTResourceManager.getImage(GMS.class, "/img/pencil_34.png"));
					btn_pencil.setToolTipText("抢画笔");
					dpc.passAuthority("0");
					userFocusIndex = -1;
					noPowerFocusIndex = focusIndex;
					noPowerTotalLabel = totalLabel;
					hasPen = false;
				}
				else{ 
					if(userFocusIndex < 0){
						dpc.requestAuthority();
					}
					else{
						lbl_penWarning.setVisible(true);
						BackgroundThread bt = new BackgroundThread(lbl_penWarning);
						bt.start();
					}
				}
			}
		});
		btn_pencil.setImage(SWTResourceManager.getImage(GMS.class, "/img/pencil_34.png"));
		btn_pencil.setToolTipText("抢画笔");
		btn_pencil.setBounds(1003, 10, 40, 40);
		
		lbl_penWarning = new Label(shlGms, SWT.NONE);
		lbl_penWarning.setAlignment(SWT.CENTER);
		lbl_penWarning.setBounds(983, 60, 80, 17);
		lbl_penWarning.setText("画笔已被抢了");
		lbl_penWarning.setVisible(false);
		
		//添加按钮
		Button btn_new = new Button(shlGms, SWT.NONE);
		btn_new.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				if(!hasPen){
					return;
				}
				lbl_lastWarning.setVisible(false);
				lbl_NDWarning.setVisible(false);
				lbl_nextWarning.setVisible(false);
				lbl_penWarning.setVisible(false);
				
				if(totalLabel == 7){
					lbl_NDWarning.setVisible(true);
					lbl_NDWarning.setText("面板已达上限");
					BackgroundThread bt = new BackgroundThread(lbl_NDWarning);
					bt.start();
				}
				else if(totalLabel == 0){
					totalLabel ++;
					ld[totalLabel].setNum();
					ld[focusIndex].lostFocus();
					focusIndex = totalLabel;
					ld[focusIndex].setFocus();
					totalLabel ++;
					
					dpc.addPanel();
					dpc.choosePanle(focusIndex);
				}
				else{
					ld[totalLabel].setNum();
					ld[focusIndex].lostFocus();
					focusIndex = totalLabel;
					ld[focusIndex].setFocus();
					totalLabel ++;
					
					dpc.addPanel();
					dpc.choosePanle(focusIndex);
				}
			}
		});
		btn_new.setToolTipText("添加新面板");
		btn_new.setImage(SWTResourceManager.getImage(GMS.class, "/img/plus_加34.png"));
		btn_new.setBounds(1098, 10, 40, 40);
		//删除按钮
		Button btn_delete = new Button(shlGms, SWT.NONE);
		btn_delete.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				if(!hasPen){
					return;
				}
				lbl_lastWarning.setVisible(false);
				lbl_NDWarning.setVisible(false);
				lbl_nextWarning.setVisible(false);
				lbl_penWarning.setVisible(false);
				
				if(totalLabel == 0){
					dpc.deletePanel(focusIndex);
					lbl_NDWarning.setVisible(true);
					lbl_NDWarning.setText("面板已全部删除");
					BackgroundThread bt = new BackgroundThread(lbl_NDWarning);
					bt.start();
				}
				else if(totalLabel == 1){
					dpc.deletePanel(focusIndex);
					totalLabel --;
				}
				else{
					dpc.deletePanel(focusIndex);
					if(focusIndex == totalLabel-1){	
						ld[focusIndex].lostFocus();
						focusIndex --;
						
						ld[focusIndex].setFocus();
						dpc.choosePanle(focusIndex);
					}
					
					ld[totalLabel-1].setNone();
					
					dpc.choosePanle(focusIndex);
				    
					totalLabel --;
				}
				
			}
		});
		btn_delete.setToolTipText("删除当前面板");
		btn_delete.setImage(SWTResourceManager.getImage(GMS.class, "/img/minus_减34.png"));
		btn_delete.setBounds(1144, 10, 40, 40);
		
		lbl_NDWarning = new Label(shlGms, SWT.NONE);
		lbl_NDWarning.setAlignment(SWT.CENTER);
		lbl_NDWarning.setBounds(1096, 60, 88, 17);
		lbl_NDWarning.setVisible(false);
		
		Button btn_share = new Button(shlGms, SWT.NONE);
		btn_share.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				if(!sm.getShareOpen()){
					sm.setDownload_x(shlGms.getLocation().x + 380);
					sm.setDownload_y(shlGms.getLocation().y + 193);
					download = new Download(sm);
					sm.setShareOpen(true);
					download.open();
				}
			}
		});
		btn_share.setToolTipText("群共享");
		btn_share.setImage(SWTResourceManager.getImage(GMS.class, "/img/folder_共享_34.png"));
		btn_share.setBounds(348, 10, 40, 40);
		
		Button btn_undo = new Button(shlGms, SWT.CENTER);
		btn_undo.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				if(!hasPen){
					return;
				}
				dpc.undo();
			}
		});
		btn_undo.setToolTipText("撤销");
		btn_undo.setImage(SWTResourceManager.getImage(GMS.class, "/img/undo_34.png"));
		btn_undo.setBounds(394, 10, 40, 40);
		
		Button btn_redo = new Button(shlGms, SWT.NONE);
		btn_redo.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				if(!hasPen){
					return;
				}
				dpc.redo();
			}
		});
		btn_redo.setToolTipText("恢复");
		btn_redo.setImage(SWTResourceManager.getImage(GMS.class, "/img/redo_34.png"));
		btn_redo.setBounds(440, 10, 40, 40);
		///******************************wbr2********************************
		//Composite composite_main = new Composite(shlGms, SWT.BORDER);
		drawPanel = new Canvas(shlGms, SWT.DOUBLE_BUFFERED);
		drawPanel.setLocation(256, 60);
		drawPanel.setSize(930, 580);
		
		drawPanel.addMouseListener((MouseListener)dpc);
		drawPanel.addMouseMoveListener((MouseMoveListener)dpc);
		drawPanel.setLayout(null);
		textInput = new StyledText(drawPanel,SWT.NONE);
		textInput.setVisible(false);
		drawPanel.addPaintListener(new PaintListener(){
			@Override
			public void paintControl(PaintEvent e) {
				dpc.draw(Display.getDefault(), e.gc,drawPanel.getBounds().width,drawPanel.getBounds().height);
			}
				
		});
		drawPanel.addKeyListener((KeyListener)dpc);
		
		drawPanel.addMouseListener(new MouseAdapter() {
			public void mouseDown(MouseEvent e){
				drawPanel.forceFocus();
			}
		});
		dpc.setTextInput(textInput);
		//dpc.addPanel();
		//dpc.choosePanle(focusIndex);
//********************************wbr2end******************************	
	}
		
	
	
	//实现小圆圈显示是否在说话的方法
	@Override
	public void updateAudioSessionState(InetSocketAddress ad, final boolean isTalk) {
		// TODO Auto-generated method stub
		//刷新已加入此房间的用户列表************************************************************************	
		/*for(int i=0;i<userList.length;i++){
			userList[i] = null;
		}
		int count = 0;
		for(User user:(ArrayList<User>)RMM.getUserList()){
			userList[count] = user;
			count ++;
		}*/
		//刷新已加入此房间的用户列表***结束*********************************************************************
		for(int i=0;i < userList.length;i++){
			if(userList[i]!=null){
				if(userList[i].getIp().equals(ad.getAddress().getHostAddress())){
					final int index = i;
					display.asyncExec(new Runnable(){
						public void run(){
							if(!shlGms.isDisposed()){
								if(isTalk){
									cu[index].setTalkImage();
								}
								else{
									cu[index].setQuietImage();
								}
							}
						}
					});
					break;
				}				
			}
		}	
	}
	//实现麦克风音量的进度条
	@Override
	public void setDB(final double DB) {
		// TODO Auto-generated method stub
		display.asyncExec(new Runnable(){
			public void run(){
		        if(!shlGms.isDisposed()){
		        	progressBar.setSelection((int) DB);
		        }
			}
		});
		
	}
	//更新聊天框内容
	@Override
	public void update(Message message) {
		// TODO Auto-generated method stub
		if(!shlGms.isDisposed()){
			final String name = message.getSenderName();
			final String con = message.getContent();
			final String time = message.getSendTime();
			display.asyncExec(new Runnable(){
				@Override
				public void run() {
					// TODO Auto-generated method stub
					if(!text_chat.isVisible()){
						tltm_chatlogs.setImage(SWTResourceManager.getImage(GMS.class, "/img/chat_30_color.png"));
					}
					String strHead = name + "  " + time;
					int startIndex = text_chat.getText().length();
					text_chat.append(strHead);
					if(name.equals(ClientUserInformations.getInstance().getUserName())){
						text_chat.setStyleRange(getColorStyle(startIndex, strHead.length(), 
								SWTResourceManager.getColor(SWT.COLOR_DARK_GREEN)));
					}
					else{
						text_chat.setStyleRange(getColorStyle(startIndex, strHead.length(), 
								SWTResourceManager.getColor(0, 153, 255)));
					}
					text_chat.append('\n' + con);
					text_chat.setSelection(text_chat.getText().length()-1);//光标移到最下方
				}				
			});
		}
		
	}
	//刷新聊天记录
	private boolean addChatlogs(){
		int chatlogsNum = 10;
		Message me_1 = tcc.readNextRocord();
		if(me_1 == null){
			return false;
		}
		
		totalChatlogsP ++;
		currentChatlogsP = totalChatlogsP;
		
		StringBuffer sb = new StringBuffer();
		sb.append(me_1.getSenderName() + "  " + me_1.getSendTime() + '\n' + me_1.getContent());
		for(int i=0;i < chatlogsNum-1;i++){
			Message me = tcc.readNextRocord();
			if(me == null){
				break;
			}
			String name = me.getSenderName();
			String time = me.getSendTime();
			String con = me.getContent();
			sb.insert(0,name + "  " + time + '\n' + con);
		}
		chatlogs[currentChatlogsP-1] = sb.toString();
		text_chatlogs.setText(chatlogs[currentChatlogsP-1]);
		lbl_chatPage.setText(currentChatlogsP + "/" + totalChatlogsP);
		return true;
	}
	//刷新用户列表
	@Override
	public void updata() {
		// TODO Auto-generated method stub
		final User[] oldUserList = new User[8];
		final User[] newUserList = new User[8];
		//导入已加入此房间的用户列表************************************************************************	
		for(int i=0;i<userList.length;i++){
			oldUserList[i] = userList[i];
			userList[i] = null;
		}
		int count = 0;
		for(User user:RMM.getUserList()){
			userList[count] = user;
			newUserList[count] = user;
			count ++;
		}	
		//导入已加入此房间的用户列表***结束*********************************************************************
		
		if(!shlGms.isDisposed() && !cu[0].getHead().isDisposed()){
			display.asyncExec(new Runnable(){
				public void run(){
					User[] oldUserList1 = new User[8];//新用户列表用于比较
					User[] newUserList1 = new User[8];//旧用户列表用于比较
					for(int i=0;i<oldUserList1.length;i++){
						oldUserList1[i] = oldUserList[i];
					}
					for(int i=0;i<newUserList1.length;i++){
						newUserList1[i] = newUserList[i];
					}
					
					//显示房间进出消息*********************************************************************************
					long timemillis = System.currentTimeMillis();	 
					SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");//转换日期显示格式  
					for(int i=0;i<oldUserList.length;i++){
						for(int j=0;j<newUserList1.length;j++){
							if(oldUserList[i] != null && newUserList1[j] != null){
								if(oldUserList[i].getId() == newUserList1[j].getId()){
									newUserList1[j] = null;
								}
							}
						}
					}
					boolean isIntoRoom = false;
					for(int i=0;i<newUserList1.length;i++){
						if(newUserList1[i] != null){
							isIntoRoom = true;
							int startIndex = text_chat.getText().length(); 
							String msg = df.format(new Date(timemillis)) + " " + newUserList1[i].getName() + " "
									+ "进入了房间" +'\n';
							text_chat.append(msg);
							text_chat.setStyleRange(getColorStyle(startIndex, msg.length(), 
									SWTResourceManager.getColor(SWT.COLOR_DARK_RED)));
							text_chat.setSelection(text_chat.getText().length()-1);//光标移到最下方
						}
					}
					if(!isIntoRoom){
						for(int i=0;i<newUserList.length;i++){
							for(int j=0;j<oldUserList1.length;j++){
								if(newUserList[i] != null && oldUserList1[j] != null){
									if(newUserList[i].getId() == oldUserList1[j].getId()){
										oldUserList1[j] = null;
									}
								}
							}
						}
						for(int i=0;i<oldUserList1.length;i++){
							if(oldUserList1[i] != null){
								int startIndex = text_chat.getText().length(); 
								String msg = df.format(new Date(timemillis)) + " " + oldUserList1[i].getName() + " " 
										+ "离开了房间" +'\n';
								text_chat.append(msg);
								text_chat.setStyleRange(getColorStyle(startIndex, msg.length(), 
										SWTResourceManager.getColor(SWT.COLOR_DARK_RED)));
								text_chat.setSelection(text_chat.getText().length()-1);//光标移到最下方
								break;
							}
						}
					}
					//显示房间进出消息***结束******************************************************************************
					
					//遍历刷新***************************************************************************	
					for(int i=0;i < cu.length;i++){
						if(userList[i] != null){
							cu[i].setVis();
							cu[i].setName(userList[i].getName());
							if(userList[i].getIp().equals(authorityIP)){
								cu[i].setFocus();
								userFocusIndex = i;
							}
							else{
								cu[i].lostFocus();
							}
						}
						else{
							cu[i].setNone();
						}
					}
					//遍历刷新***结束**********************************************************************			
				}
			});
		}
		
	}
	
	//composite组件缓慢显示***********************************************************************************
	//从右到左慢慢展开
	public void toLeftSlowly(final Composite composite,final int width,final int startX){
		composite.setSize(0, composite.getSize().y);
		new Thread(new Runnable() {
		    private int startWidth = 0;
		    public void run() {
		        while (startWidth <= width) {
		            composite.getDisplay().syncExec(new Runnable() {
		                public void run() {
		                	startWidth = startWidth + 25;
		                	composite.setSize(startWidth, composite.getSize().y);
		                	composite.setLocation(startX + width - startWidth, composite.getLocation().y);
		                }
		            });
		            Thread.yield();// 暂停
		        }
		    }
		}).start();
	}
	
	//从左到右慢慢消失
	public void toRightSlowlyDisappear(final Composite composite,final int width,final int startX){
		new Thread(new Runnable() {
		    private int startWidth = width;
		    public void run() {
		        while (startWidth > 0) {
		            composite.getDisplay().syncExec(new Runnable() {
		                public void run() {
		                	startWidth = startWidth - 25;
		                	//composite.setSize(startWidth, composite.getSize().y);
		                	composite.setLocation(startX + width - startWidth, composite.getLocation().y);
		                	//System.out.println(startWidth);
		                }
		            });
		            Thread.yield();// 暂停
		        }
		    }
		}).start();
	}
	//从左到右慢慢展开  可以只变location
	public void toRightSlowly(final Composite composite,final int width,final int startX){
		new Thread(new Runnable() {
		    private int startWidth = 0;
		    public void run() {
		        while (startWidth <= width) {
		            composite.getDisplay().syncExec(new Runnable() {
		                public void run() {
		                	startWidth = startWidth + 25;
		                	composite.setSize(startWidth, composite.getSize().y);
		                }
		            });
		            Thread.yield(); // 暂停
		        }
		    }
		}).start();
	}
	//从右到左慢慢消失 可以只变location
	public void toLeftSlowlyDisappear(final Composite composite,final int width,final int startX){
		new Thread(new Runnable() {
		    private int startWidth = width;
		    public void run() {
		        while (startWidth > 0) {
		            composite.getDisplay().syncExec(new Runnable() {
		                public void run() {
		                	startWidth = startWidth -25;
		                	composite.setSize(startWidth, composite.getSize().y);
		                }
		            });
		            Thread.yield(); // 暂停
		        }
		    }
		}).start();
	}
	
	//主界面慢慢消失
	public void SlowlyDisappear(final Shell shell,final int height,final int startY){
		new Thread(new Runnable() {
		    private int startHeight = height;
		    public void run() {
		        while (startHeight > 0){
		            shell.getDisplay().syncExec(new Runnable() {
		                public void run() {
		                	startHeight = startHeight - 20;
		                	shell.setSize(shell.getSize().x, startHeight);
		                	shell.setLocation(shell.getLocation().x, startY + (height - startHeight)/2);
		                	//System.out.println(startHeight);
		                }
		            });
		            Thread.yield();// 暂停
		        } 
		        shell.getDisplay().syncExec(new Runnable() {

					@Override
					public void run() {
						// TODO Auto-generated method stub
						shell.setVisible(false);
						shell.dispose();
					}
		        	
		        });
		        
		    }
		}).start();
	}
	
	//composite组件缓慢显示***结束***********************************************************************
	
	//清空一个路径中所有文件的方法************************************************************************
	public void deleteFile(File file){
		if(file.exists()){
			if(file.isFile()){
				file.delete();
			}
			else if(file.isDirectory()){
				File[] files = file.listFiles();
				for(int i=0;i<files.length;i++){
					this.deleteFile(files[i]);//迭代删除
				}
				file.delete();
			}
		}
		else{
			System.out.println("文件名不存在！");
		}
	}
	//清空一个路径中所有文件的方法***结束******************************************************************
	
	//后台线程类************************************************************************************
	class BackgroundThread extends Thread{
		private Label label;
		
		public BackgroundThread(Label label){
			this.label = label;
		}
		
		public void run(){
			try {
				sleep(2000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			if(!shlGms.isDisposed()){
				display.asyncExec(new Runnable() {
					
					@Override
					public void run() {
						// TODO Auto-generated method stub
						label.setVisible(false);
					}
				});
			}
		}
	}
	//后台线程类***结束*********************************************************************************
	//
	//后台线程类之传递权利************************************************************************************
	class PowerInfoThread extends Thread{
		private String str;
		
		public PowerInfoThread(String str){
			this.str = str;
		}
		
		public void run(){
			display.asyncExec(new Runnable() {
				
				@Override
				public void run() {
					// TODO Auto-generated method stub
					lbl_powerInfo.setText(str);
					lbl_powerInfo.setVisible(true);
					text_chat.setBounds(10, 133, 216, 305);
					text_chatlogs.setBounds(10, 133, 216, 278);
				}
			});
			try {
				sleep(2000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			if(!shlGms.isDisposed()){
				display.asyncExec(new Runnable() {
					
					@Override
					public void run() {
						// TODO Auto-generated method stub
						lbl_powerInfo.setVisible(false);
						text_chat.setBounds(10, 111, 216, 327);
						text_chatlogs.setBounds(10, 111, 216, 300);
					}
				});
			}
		}
	}
	//后台线程类之传递权利***结束*******************************************************************************
	
	//实现添加删除面板观察者的方法****************************************************************************
	@Override
	public void addPanel() {
		// TODO Auto-generated method stub
		if(hasPen){
			return;
		}
		display.asyncExec(new Runnable() {
			
			@Override
			public void run() {
				// TODO Auto-generated method stub
				if(noPowerTotalLabel == 0){
					noPowerTotalLabel = 2;
					ld[noPowerTotalLabel-1].setNum();
				}
				else{
					noPowerTotalLabel ++;		
					ld[noPowerTotalLabel-1].setNum();
				}
				
			}
		});
		
	}

	@Override
	public void deletePanel() {
		// TODO Auto-generated method stub
		if(hasPen){
			return;
		}
		display.asyncExec(new Runnable() {
			
			@Override
			public void run() {
				if(noPowerTotalLabel == 1){
					noPowerTotalLabel --;
				}
				else{/*
					if(noPowerFocusIndex == noPowerTotalLabel-1){
						ld[noPowerFocusIndex].lostFocus();
						noPowerFocusIndex --;
						ld[noPowerFocusIndex].setFocus();
					}*/
					ld[noPowerTotalLabel-1].setNone();
					noPowerTotalLabel --;
				}
			}
		});
		
	}

	@Override
	public void choosePanel(int index) {
		// TODO Auto-generated method stub
		if(hasPen){
			return;
		}
		final int i = index;
		display.asyncExec(new Runnable() {
			
			@Override
			public void run() {
				ld[noPowerFocusIndex].lostFocus();
				noPowerFocusIndex = i;
				ld[noPowerFocusIndex].setFocus();
			}
		});
		
	}
	//实现添加删除面板观察者的方法***结束*************************************************************************
	
	//读取txt文件操作**********************************************************************************
	private void readTxt(){
		file = new File("documents\\" + roomID);
		if(!file.exists()){
			file.mkdir();
		}
		fList = file.listFiles();
		
		for(int i=0;i < fList.length;i++){
			if(!fList[i].isDirectory()){
				if(totalPage == MAX_TXT){
					break;	
				}
				try {
					String readStr = "";
					String read = "";
					BufferedReader br = new BufferedReader(new FileReader(fList[i]));
					while((read = br.readLine()) != null){
						readStr = readStr + read + "\n";
					}
					textString[i] = readStr;
					totalPage ++;
					br.close();
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		//如果一个文件也没有，将总页数设成1
		if(totalPage == 0){
			totalPage = 1;
			textString[0] = "";
		}
	}
	//读取txt文件操作***结束****************************************************************************	
	
	//保存txt文件操作********************************************************************************
	private void saveTxt(){
		textString[currentPage-1] = text.getText();
		//System.out.println("保存，当前面板字符" + text.getText());
		for(int i=0;i<fList.length;i++){
			deleteFile(fList[i]);
		}
		for(int i=0;i<totalPage;i++){
			try {
				BufferedWriter bw = new BufferedWriter(new FileWriter("documents/" + roomID + "/" + i +".txt"));
				//System.out.println("保存，字符数组"+textString[i]);
				bw.write(textString[i]);
				bw.close();
			} catch (IOException ioe) {
				// TODO Auto-generated catch block
				ioe.printStackTrace();
			}
		}
	}
	//保存txt文件操作***结束*************************************************************************	

	@Override
	public synchronized void exceptionInfo(Exception Exception) {
		// TODO Auto-generated method stub
		
	}
	//styledText设置部分字体颜色
	private  StyleRange getColorStyle( int  startOffset,  int  length, Color color)  {
		StyleRange styleRange  =   new  StyleRange(startOffset, length, color,  null );
		styleRange.fontStyle  =  SWT.BOLD;
        return  styleRange;
	} 
}
